//************************************************************************
//Developed by Guo Ming Li 2009/2010
//Source code:
//  The source code may be freely modified or used but this credit section may not be removed 
//  The original author must be notified of any modifications plus a copy of 
//  the changed source code
//Contact info: mailto://gming.li@gmail.com
//************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using GML.BizTalk.OperationManager.Library;

namespace GML.BizTalk.OperationManager.MSBTSOperations
{
    public partial class GACEntry
    {
        //private GACVerificationFilter filter;

        public GACEntry() { }

        //public GACEntry(GACVerificationFilter _filter)
        //{
        //    this.filter = _filter;
        //}

        public GACEntry(string sAssemblyLUID)
        {
            AssemblyName name = new AssemblyName(sAssemblyLUID);
            this.AssemblyCulture = (((name.CultureInfo != null) && (name.CultureInfo.Name != null)) && (name.CultureInfo.Name.Length > 0)) ? name.CultureInfo.Name : "neutral";
            this.AssemblyPublicKeyToken = Helper.ByteArrayToHexString(name.GetPublicKeyToken());
            this.AssemblyName = name.Name;
            this.AssemblyVersion = name.Version.ToString();
            name = null;
            

        }
        public override string ToString()
        {
            return AssemblyName + ", Version=" + AssemblyVersion.ToString() + ", Culture=" + AssemblyCulture + ", PublicKeyToken=" + AssemblyPublicKeyToken;
        }

        public string ToLongString(GACVerificationFilter comparisonFilter)
        {
            return AssemblyName
                    + ", Version=" + AssemblyVersion.ToString()
                    + ", Culture=" + AssemblyCulture
                    + ", PublicKeyToken=" + AssemblyPublicKeyToken
                    + (comparisonFilter.CheckAssemblyFileSize ? (", AssemblyFileSize=" + AssemblyFileSize) : (string.Empty))
                    + (comparisonFilter.CheckAssemblyFileVersion ? (", AssemblyFileVersion=" + AssemblyFileVersion) : (string.Empty))
                    + (comparisonFilter.CheckAssemblyProductVersion ? (", AssemblyProductVersion=" + AssemblyProductVersion) : (string.Empty))
                    + (comparisonFilter.CheckAssemblyPath ? (", AssemblyPaths=" + AssemblyPaths) : (string.Empty))
                    + (comparisonFilter.CheckCreateDate ? (", CreateDate=" + CreateDate) : (string.Empty))
                    + (comparisonFilter.CheckMachineName ? (", MachineName=" + MachineName) : (string.Empty))
                    ;
        }
        public string ToString(GACVerificationFilter comparisonFilter)
        {
            return AssemblyName
                    + ", Version=" + AssemblyVersion.ToString()
                    + ", Culture=" + AssemblyCulture
                    + ", PublicKeyToken=" + AssemblyPublicKeyToken
                    + (comparisonFilter.CheckAssemblyFileSize ? (", AssemblyFileSize=" + AssemblyFileSize) : (string.Empty))
                    + (comparisonFilter.CheckAssemblyFileVersion ? (", AssemblyFileVersion=" + AssemblyFileVersion) : (string.Empty))
                    + (comparisonFilter.CheckAssemblyProductVersion ? (", AssemblyProductVersion=" + AssemblyProductVersion) : (string.Empty))
                    + (comparisonFilter.CheckAssemblyPath ? (", AssemblyPaths=" + AssemblyPaths) : (string.Empty))
                    + (comparisonFilter.CheckCreateDate ? (", CreateDate=" + CreateDate) : (string.Empty))
                    + (comparisonFilter.CheckMachineName ? (", MachineName=" + MachineName) : (string.Empty))
                    ;
        }

        public bool Equals(GACEntry compareTo, GACVerificationFilter comparisonFilter)
        {
            return
                (comparisonFilter.CheckAssemblyName ? (this.AssemblyName == compareTo.AssemblyName) : true) &&
                (comparisonFilter.CheckAssemblyVersion ? (this.AssemblyVersion.Equals(compareTo.AssemblyVersion)) : true) &&
                (comparisonFilter.CheckAssemblyCulture ? (this.AssemblyCulture == compareTo.AssemblyCulture) : true) &&
                (comparisonFilter.CheckAssemblyPublicKeyToken ? (this.AssemblyPublicKeyToken == compareTo.AssemblyPublicKeyToken) : true) &&
                (comparisonFilter.CheckAssemblyFileSize ? (this.AssemblyFileSize == compareTo.AssemblyFileSize) : true) &&
                (comparisonFilter.CheckAssemblyFileVersion ? (this.AssemblyFileVersion == compareTo.AssemblyFileVersion) : true) &&
                (comparisonFilter.CheckAssemblyProductVersion ? (this.AssemblyProductVersion == compareTo.AssemblyProductVersion) : true) &&
                (comparisonFilter.CheckAssemblyPath ? (this.AssemblyPaths == compareTo.AssemblyPaths) : true) &&
                (comparisonFilter.CheckCreateDate ? (this.CreateDate == compareTo.CreateDate) : true) &&
                (comparisonFilter.CheckMachineName ? (this.MachineName == compareTo.MachineName) : true);
        }
    }
}
